const mongoose = require('mongoose');


// 定义地址集合的 Schema（数据结构）
const AddressSchema = new mongoose.Schema({
    recipient: {
        type: String,
        required: true, // 必传字段
        trim: true // 去除首尾空格
    },
    phone: {
        type: String,
        required: true,
        trim: true
    },
    provinceCode: {
        type: String,
        required: true
    },
    provinceName: {
        type: String,
        required: true
    },
    cityCode: {
        type: String,
        required: true
    },
    cityName: {
        type: String,
        required: true
    },
    districtCode: {
        type: String,
        required: true
    },
    districtName: {
        type: String,
        required: true
    },
    detailAddress: {
        type: String,
        required: true,
        trim: true
    },
    isDefault: {
        type: Boolean,
        default: false // 默认不是默认地址
    },
    createTime: {
        type: Date,
        default: Date.now // 默认当前时间
    },
    logId:{
        type:mongoose.Types.ObjectId,
        ref:"logins"
    }
});

// 创建模型
const Address = mongoose.model('address', AddressSchema);

module.exports = { Address }; 